package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.CommunityChargeVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CommunityCharge;
import com.ruoyi.system.service.ICommunityChargeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * chargeController
 *
 * @author wanglong
 * @date 2024-03-24
 */
@RestController
@RequestMapping("/system/charge")
public class CommunityChargeController extends BaseController
{
    @Autowired
    private ICommunityChargeService communityChargeService;


    /**
     * 查询charge列表
     */
    @PreAuthorize("@ss.hasPermi('system:charge:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityCharge communityCharge)
    {
        // 根据前端的要求进行自动分页
        startPage();
        List<CommunityCharge> list = communityChargeService.selectCommunityChargeList(communityCharge);
        return getDataTable(list);
    }
    /**
     * 查询charge列表
     */
    @PreAuthorize("@ss.hasPermi('system:charge:sum')")
    @GetMapping("/sum")
    @ApiOperation("统计水电费物业费")
    public AjaxResult list(CommunityChargeVo communityCharge)
    {
        return success(communityChargeService.selectCommunityChargeSum(communityCharge));
    }

    /**
     * 导出charge列表
     */
    @PreAuthorize("@ss.hasPermi('system:charge:export')")
    @Log(title = "charge", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityCharge communityCharge)
    {
        List<CommunityCharge> list = communityChargeService.selectCommunityChargeList(communityCharge);
        ExcelUtil<CommunityCharge> util = new ExcelUtil<CommunityCharge>(CommunityCharge.class);
        util.exportExcel(response, list, "charge数据");
    }

    /**
     * 获取charge详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:charge:query')")
    @GetMapping(value = "/{chargeId}")
    public AjaxResult getInfo(@PathVariable("chargeId") Long chargeId)
    {
        return success(communityChargeService.selectCommunityChargeByChargeId(chargeId));
    }

    /**
     * 新增charge
     */
    @PreAuthorize("@ss.hasPermi('system:charge:add')")
    @Log(title = "charge", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityCharge communityCharge)
    {
        return toAjax(communityChargeService.insertCommunityCharge(communityCharge));
    }

    /**
     * 修改charge
     */
    @PreAuthorize("@ss.hasPermi('system:charge:edit')")
    @Log(title = "charge", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityCharge communityCharge)
    {
        return toAjax(communityChargeService.updateCommunityCharge(communityCharge));
    }

    /**
     * 删除charge
     */
    @PreAuthorize("@ss.hasPermi('system:charge:remove')")
    @Log(title = "charge", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chargeIds}")
    public AjaxResult remove(@PathVariable Long[] chargeIds)
    {
        return toAjax(communityChargeService.deleteCommunityChargeByChargeIds(chargeIds));
    }
}
